package enumdemo;

import com.sun.org.apache.regexp.internal.RE;

/**
 * @Author 12629
 * @Date 2022/4/4 19:51
 * @Description：
 */
//我们自己写的枚举类  都默认继承与Enum
public enum TestEnum {
    RED("红色",1),GREEN("绿色",2),
    BLACK("黑色",3);//枚举对象

    public String color;
    public int ordinal;

    /**
     * 枚举的构造方法！ 默认是私有的
     * @param color
     * @param ordinal
     */
    TestEnum(String color, int ordinal) {
        this.color = color;
        this.ordinal = ordinal;
    }

    public static void main2(String[] args) {
        //TODO: .values()在哪里？？？
        TestEnum[] array = TestEnum.values();
        for (int i = 0; i < array.length; i++) {
            System.out.println(array[i]+" " + array[i].ordinal());
        }
        System.out.println("=========");
        TestEnum test = TestEnum.valueOf("RED");
        System.out.println(test);
        System.out.println("=========");
        System.out.println(RED.compareTo(BLACK));
    }

    public static void main1(String[] args) {
        TestEnum testEnum2 = TestEnum.BLACK;
        switch (testEnum2) {
            case RED:
                System.out.println("red");
                break;
            case GREEN:
                System.out.println("GREEN");
                break;
            case BLACK:
                System.out.println("black");
                break;
            default:
                break;
        }
    }
}
